package cn.nexd.app.collector.presenter.splash;


import android.Manifest;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.Log;

import com.mylhyl.acp.Acp;
import com.mylhyl.acp.AcpListener;
import com.mylhyl.acp.AcpOptions;

import java.io.File;
import java.util.List;

import cn.nexd.app.collector.application.NexdApplication;
import cn.nexd.app.collector.presenter.db.NexdSqlOpenHelper;
import cn.nexd.app.collector.presenter.network.HttpMethod;


/**
 * Created by xun on 2016/8/2.
 */
public class LoadDataPresenter implements LoadDataContract.Presenter {
    private final LoadDataContract.View loadView;
    private String TAG = "LoadDataPresenter";
    private NexdSqlOpenHelper databaseHelp;
    private HttpMethod httpMethod;
    private Context mContext;
    private Acp acp;


    public LoadDataPresenter(LoadDataContract.View loadView, Context context) {
        this.loadView = loadView;
        this.mContext = (Context) loadView;
        this.httpMethod = HttpMethod.getInstance(context);
        this.databaseHelp = NexdApplication.getInstance().getSqlHelper();
        this.acp = Acp.getInstance(mContext);
        init();
    }

    @Override
    public void init() {
        File file = new File(NexdApplication.BASE_FILE_PATH);
        Log.d("LoadDataPresenter", "file.isDirectory():" + file.isDirectory());

    }


    @TargetApi(Build.VERSION_CODES.M)
    @Override
    public void checkPermission() {

        acp.request(new AcpOptions.Builder()
                .setPermissions(Manifest.permission.READ_PHONE_STATE)
                .setDeniedMessage("您拒绝读取手机状态权限将不能正常使用，请到设置界面重新授权").build(), new AcpListener() {
            @Override
            public void onGranted() {
                loadView.startActivity();
            }

            @Override
            public void onDenied(List<String> permissions) {
                loadView.showToast("请打开读取手机信息权限");
            }
        });
    }
}


